var menu = {
	id:0,
	name:"",
	icon:"",// https://materialdesignicons.com/cdn/2.0.46/
	url:"",
	children:[]
	
};

var demoMenus = [
		//******************/
	{
		id:1,
		name:"测试",
		icon:"fa fa-fw fa-table",//mdi-football
		url:"",
		children:[
			{
				id:1001,
				name:"测试一",
				icon:"",
				url:"lcxm_test1.html",
				children:[]
				
			},
			{
				id:1002,
				name:"测试二",
				icon:"",
				url:"lcxm_test2.html",
				children:[]
				
			},
			{
				id:1003,
				name:"测试三",
				icon:"mdi-football m-r-10",
				url:"",
				children:[
					{
					id:1003001,
					name:"测试三子菜单",
					icon:"",
					url:"lcxm_test2.html",
					children:[]
				
					}
				]
				
			}
		]
	},
	{
		id:2,
		name:"JS插件",
		icon:"mdi mdi-language-javascript",
		url:"",
		children:[
			{
				id:2002,
				name:"bootstrap-table",
				icon:"mdi mdi-table-large",
				url:"module/test/bootstrap-table/bootstrap-table.html",
				children:[]
				
			},
			{
				id:2003,
				name:"数据绑定",
				icon:"mdi mdi-swap-horizontal",
				url:"module/test/pandyle/pandyle1.html",
				children:[]
				
			}
		]
	},
	{
		id:3,
		name:"其他",
		icon:"fa fa-window-restore",
		url:"",
		children:[
			{
				id:3001,
				name:"代码生成",
				icon:"fa fa-table",
				url:"lcxm_other_generator.html",
				children:[]
				
			},
			{
				id:3001,
				name:"form",
				icon:"fa fa-table",
				url:"lcxm_other_generator_form.html",
				children:[]
				
			},
		]
	}

];
/* ******************************************************************************************/

$(function(){
	var initMenu = {
		opt:{
			template:{
				parent: $(`<li class="nav-item nav-item-has-subnav">
							<a href="javascript:void(0)"><i class=" "></i></a>
							<ul class="nav nav-subnav"></ul>
						</li>`),
				child:$(`<li>
						<a class="multitabs" href="#!"><i class=" "></i></a>
						</li>`)
					}
		},
		init: function($root,datas){
			var module = this;
			if(!data ){
				return;
			}
			Array.prototype.slice.call(datas).forEach(function(data, index){
				var $menu = module.buildMenuDocument(data);
				$root.append($menu);
			});
		},
		buildMenuDocument: function(data){
			var module = this;
			if(data.children.length >0){ // 包含子菜单
				return module.buildFather(data);
			}else {
				return module.buildChild(data);
			}
		},
		buildChild: function(data){
			return this.opt.template.child.clone().find("a").attr("href", data.url)
			.find("i").addClass(data.icon).after('<span>'+data.name+'</span>').end().end();
			
		},
		buildFather: function(data){
			var module = this;
			var $father = module.opt.template.parent.clone();
			$father.find("a:first i").addClass(data.icon).after('<span>'+data.name+'</span>');
			var $ul = $("ul", $father);
			var childrenData = data.children;
			data.children.forEach(function(d, index){
				if(d.children.length > 0){
					$ul.append(module.buildFather(d));
				}else {
					$ul.append(module.buildChild(d));
				}
			});
			return $father;
		}
	};
	
	
	var $root = $("ul.nav-drawer");
	var data = demoMenus;
	//initMenu.init($root, data);
	
});
